package com.wuneng.ircontrol.module.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.wuneng.ircontrol.R;
import com.clj.fastble.data.BleDevice;

import java.util.ArrayList;
import java.util.List;

public class BleAdapter extends BaseAdapter {
    private Context context;


    private List<BleDevice> datas = new ArrayList<>();

    public BleAdapter(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = LayoutInflater.from(context).inflate(R.layout.item_bluetooth, null);
        TextView tvDevice = (TextView) convertView.findViewById(R.id.tvDevice);

        if (!TextUtils.isEmpty(datas.get(position).getName())) {
            tvDevice.setText(datas.get(position).getName());
        } else {
            tvDevice.setText(datas.get(position).getMac());
        }
        return convertView;
    }

    public void refresh(List<BleDevice> lists) {
        this.datas = lists;
        notifyDataSetChanged();
    }

}
